package com.chenyaowei.quartz.task;

import cn.hutool.core.collection.CollectionUtil;
import com.chenyaowei.order.domain.CywOrder;
import com.chenyaowei.order.enums.OrderStatusEnum;
import com.chenyaowei.order.service.ICywOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * TODO mq
 * 超时订单解锁库存定时任务
 */
@Component("orderUnlockTask")
public class OrderUnlockTask {

    @Autowired
    private ICywOrderService orderService;

    public void orderUnlock(){
        System.out.println("订单解锁库存定时任务开始执行");
        // 1.查询超时订单
        List<CywOrder> timeOutOrderList  = orderService.selectTimeOutOrderList();
        // TODO 再发支付宝查单接口，核对订单状态
        // 2.取消订单、解锁库存
        if (CollectionUtil.isNotEmpty(timeOutOrderList)){
            timeOutOrderList.forEach(item -> {
                orderService.cancelOrder(item.getOrderSn(), OrderStatusEnum.TIME_OUT_CLOSE.getCode() );
            });
        }

    }

}
